﻿Imports System
Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip
Imports ICSharpCode.SharpZipLib.Core
Imports System.Threading.Tasks
Imports System.Windows.Forms

Public Class BackupAndRestore
    Dim _path As String
    Public Sub New()
        _path = ""
    End Sub

    Public Sub New(ByVal path As String)
        _path = path.Trim
    End Sub

    Public Sub Backup(ByVal targetName As String, Optional ByVal sourceDir As String = "")
        If String.IsNullOrEmpty(sourceDir) Then
            sourceDir = _path
        End If

        Dim fastzip As New FastZip
        fastzip.CreateZip(targetName, sourceDir, True, Nothing)
    End Sub


    Dim _stop As Boolean = Nothing
    ''' <summary>
    ''' Stellt die Dateien aus einer Sicherung wieder her
    ''' </summary>
    ''' <param name="sourcefile">Quell-ZipDatei</param>
    ''' <param name="targetDir">Zielverzeichnis</param>
    ''' <remarks></remarks>
    Public Sub Wiederherstellen(ByVal sourcefile As String, Optional targetDir As String = "")
        If String.IsNullOrEmpty(targetDir) Then
            targetDir = _path
        End If

        Dim fastZip As FastZip = New FastZip() '(events)

        ' The only way to conditionally extraxt files in FastZip is to use the fileFilter and directoryFilter arguments.
        ' The filter is a list of regex values separated with semi-colon. An entry starting with - is an exclusion.
        ' See the NameFilter class for more examples.
        ' The following expression includes all name ending in '.dat' with the exception of 'dummy.dat'
        Dim fileFilter As String = Nothing ' "+\.dat$;-^dummy\.dat$"
        Dim directoryFilter As String = Nothing
        Dim restoreDateTime As Boolean = True

        ' Will prompt to overwrite if target filenames already exist
        fastZip.ExtractZip(sourcefile, targetDir, Nothing)
    End Sub
End Class
